﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZhongheCms.Models;
using GsnHelper;
namespace ZhongheCms.Controllers
{
    public class ResumeController : Controller
    {
        //
        // GET: /Resume/

        public ActionResult Index(int id = 0, string m = "", string f = "", string p = "", string fid = "", string sdate = "", string edate = "", string keywords = "")
        {
            ViewBag.m = m;
            ViewBag.f = f;
            ViewBag.p = p;
            ViewBag.fid = fid;
            ViewBag.keywords = keywords;
            ViewBag.sdate = sdate;
            ViewBag.edate = edate;
            if (GswTblUser.CurrentUser == null)
                return RedirectToAction("Login", "Account");
            GswTblUser.CurrentUser.ModuleName = m;
            GswTblUser.CurrentUser.FuncName = f;
            var sql = "where CustomerId=" + GswTblUser.CurrentUser.CustomerId;
            if (InputValid.IsDate(sdate))
                sql += " and RegDate='" + sdate + "'";
            if (InputValid.IsDate(edate))
                sql += " and RegDate='" + edate + "'";
            if (!string.IsNullOrEmpty(keywords))
                sql += " and (JobTitle like '%" + keywords + "%' or WorkName  like '%" + keywords + "%')";
            sql += " order by RegDate desc";
            var qry = GswViewResume.Fetch(sql);

            return View(qry);
        }

        public ActionResult ResumeView(int id = 0, string m = "", string f = "", string p = "", string fid = "",
            string sdate = "", string edate = "", string keywords = "")
        {
            ViewBag.m = m;
            ViewBag.f = f;
            ViewBag.p = p;
            ViewBag.fid = fid;
            ViewBag.keywords = keywords;
            ViewBag.sdate = sdate;
            ViewBag.edate = edate;
            if (GswTblUser.CurrentUser == null)
                return RedirectToAction("Login", "Account");
            GswTblUser.CurrentUser.ModuleName = m;
            GswTblUser.CurrentUser.FuncName = f;
            var qry = GswViewResume.SingleOrDefault(id);
            return View(qry);
        }

        public ActionResult Delete(int id = 0, string m = "", string f = "", string p = "", string fid = "",
            string sdate = "", string edate = "", string keywords = "")
        {
            ViewBag.f = f;
            ViewBag.p = p;
            ViewBag.fid = fid;
            ViewBag.keywords = keywords;
            ViewBag.sdate = sdate;
            ViewBag.edate = edate;
            if (GswTblUser.CurrentUser == null)
                return RedirectToAction("Login", "Account");
            GswTblUser.CurrentUser.ModuleName = m;
            GswTblUser.CurrentUser.FuncName = f;
            GswTblResume.Delete(id);
            var sql = "where CustomerId=" + GswTblUser.CurrentUser.CustomerId + " and FunctionId=" + fid;
            if (InputValid.IsDate(sdate))
                sql += " and RegDate='" + sdate + "'";
            if (InputValid.IsDate(edate))
                sql += " and RegDate='" + edate + "'";
            if (!string.IsNullOrEmpty(keywords))
                sql += " and (JobTitle like '%" + keywords + "%' or WorkName  like '%" + keywords + "%')";
            sql += " order by RegDate desc";
            var qry = GswViewResume.Fetch(sql);
            return View("Index", qry);

        }
    }
}
